<!-- 修改密码表单 -->
<form class="layui-form model-form">
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">原始密码:</label>
        <div class="layui-input-block">
            <input type="password" name="oldPsw" placeholder="请输入原始密码" class="layui-input"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">新密码:</label>
        <div class="layui-input-block">
            <input type="password" name="password" placeholder="请输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|psw" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">确认密码:</label>
        <div class="layui-input-block">
            <input type="password" name="rePsw" placeholder="请再次输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|equalTo" lay-equalTo="input[name=password]" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
            <button class="layui-btn" lay-filter="submit-psw" lay-submit>保存</button>
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'form', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;

        admin.iframeAuto();  // 让当前iframe弹层高度适应

        // 监听提交
        form.on('submit(submit-psw)', function (data) {
            layer.load(2);
            $.post('../system/user/restPsw', data.field, function (res) {
                if (res.code == 200) {
                    layer.closeAll('loading');
                    layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                        top.location.replace('../logout');
                    });
                } else {
                    layer.closeAll('loading');
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });

        // 添加表单验证方法
        form.verify({
            psw: [/^[\S]{2,12}$/, '密码必须2到12位，且不能出现空格'],
            repsw: function (t) {
                if (t !== $('input[name=password]').val()) {
                    return '两次密码输入不一致';
                }
            }
        });

    });
</script>
</body>
</html>